<?php
require_once './db.php';
require_once './field/admin_user_field_util.php';
/**
 *
 */
class AdminUserModel extends Db
{

    private $fieldUtil;

    public function __construct(AdminUserFileUtil $fieldUtil)
    {
        $this->fieldUtil = $fieldUtil;
        parent::__construct();
    }

    public function getFieldUtil()
    {
        return $this->fieldUtil;
    }
    /**
     * 随机一条数据
     * @return [type] [description]
     */
    public function randInsert()
    {
        $sql = "insert into admin_user (user_name, `password`, role_id,real_name)values('".$this->getFieldUtil()->userName()."','".$this->getFieldUtil()->password()."',".$this->getFieldUtil()->roleId().",'".$this->getFieldUtil()->realName()."')";

        $this->insert($sql);
    }
    /**
     * 随机多条条数据
     * @return [type] [description]
     */
    public function randInserts($count = 3)
    {
        $sqlPrefix = "insert into admin_user (user_name, `password`, role_id,real_name)values";
        $sqlSuffix = "";
        for ($i=0; $i < $count; $i++) {
            $sqlSuffix = $sqlSuffix."('".$this->getFieldUtil()->userName()."','".$this->getFieldUtil()->password()."',".$this->getFieldUtil()->roleId().",'".$this->getFieldUtil()->realName()."'),";
        }
        $sqlSuffix = substr($sqlSuffix, 0, -1) ;

        $this->insert($sqlPrefix.$sqlSuffix, $count);
    }

    public function insert($sql, $count = 1)
    {
        if($this->execute($sql) > 0) {
            // var_dump( '随机'.$count.'条数据 -- 成功');
        } else {
            // var_dump($this->getError());
        };
    }

}
$adminUser = new AdminUserModel(new AdminUserFileUtil());
